<?php 
/**** 
xajax通用分页类 
**适用于无刷新页面翻页 
**未提供注释，博君一笑~~ 
** @author : lino(luckfeng@gmail.com) 
** @site : http://www.ypren.com 
** @version : 0.2 
** @date : 2006/2/16 
**/ 

class Pager 
{ 
var $url; 
var $countall; 
var $page; 
var $thestr; 
var $backstr; 
var $nextstr; 
var $pg; 
var $content; 
var $function; 
var $id; 

function Pager($countall,$countlist,$id,$function,$thePage) 
{ 
// 参数分别为:总数,每页显示数,操作的ID，操作的方法，当前页 

$this->function = $function; 
$this->id = $id; 
if ($thePage==0 || $thePage=="") 
{ 
$thePage = 1; 
} 
$this->pg = $thePage; 
$this->countall = $countall; 
if ($this->countall%$countlist!=0) 
{ 
$this->page=sprintf("%d",$this->countall/$countlist)+1; 
} 
else 
{ 
$this->page=$this->countall/$countlist; 
} 
if ($this->page<=10) 
{ 
for ($i=1;$i<$this->page+1;$i++) 
{ 
$this->thestr=$this->thestr.Pager::makepg($i,$this->pg); 
} 
} 
else 
{ 
if ($this->pg<=5) 
{ 
for ($i=1;$i<10;$i++) 
{ 
$this->thestr=$this->thestr.Pager::makepg($i,$this->pg); 
} 
} 
else 
{ 
if (6+$this->pg<=$this->page) 
{ 
for ($i=$this->pg-4;$i<$this->pg+6;$i++) 
{ 
$this->thestr=$this->thestr.Pager::makepg($i,$this->pg); 
} 
} 
else 
{ 
for ($i=$this->pg-4;$i<$this->page+1;$i++) 
{ 
$this->thestr=$this->thestr.Pager::makepg($i,$this->pg); 
} 
} 
} 
} 
$this->backstr = Pager::gotoback($this->pg); 
$this->nextstr = Pager::gotonext($this->pg,$this->page); 
$this->content = $this->backstr.$this->thestr.$this->nextstr." 共".$this->countall." 条,每页".$countlist."条，分".$this->page."页 当前第".$thePage."页"; 
return $this->content; 
} 

function makepg($i,$pg) 
{ 
if ($i==$pg) 
{ 
return " ".$i.""; 
} 
else 
{ 
return " ".$i.""; 
} 
} 

function gotoback($pg) 
{ 
if ($pg-1>0) 
{ 
$pg = $pg-1; 
return $this->gotoback=" 首页 上页"; 
} 
else 
{ 
return $this->gotoback=""; 
} 
} 

function gotonext($pg,$page) 
{ 
if ($pg < $page) 
{ 
$pg = $pg+1; 
return " 下页 尾页"; 
} 
else 
{ 
return ""; 
} 
} 
} 
?>